/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  房间座位
	/// module : room
	/// </summary>
	public class RoomSeatPod : IPOD 
    {
        public readonly static Func<RoomSeatPod> FACTORY = () => new RoomSeatPod();
		public static Func<RoomSeatPod> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  座位号，1开始
        /// </summary>
		public int seatNum;
		/// <summary>
        ///  是否被关闭，不可用
        /// </summary>
		public bool closed;
		/// <summary>
        ///  玩家信息
        /// </summary>
		public PlayerShowPOD player;
		
		
		
		/*-- constructors --*/
		public RoomSeatPod() {}
		public RoomSeatPod(int seatNum, bool closed, PlayerShowPOD player) {
			this.seatNum = seatNum;
			this.closed = closed;
			this.player = player;
		}
		  public void Serial(SOutputStream _out) {
                if(seatNum != default) {
                    _out.WriteByte(1);
                    _out.Write_int(seatNum);
                }
                if(closed != default) {
                    _out.WriteByte(2);
                    _out.Write_boolean(closed);
                }
                if(player != default) {
                    _out.WriteByte(3);
                    _out.Write_pod(player);
                }
        }
            
        public void UnSerial(SInputStream _in) {
            while (_in.HasRemaining())
            {
                int _key = _in.ReadByte();
                switch (_key)
                {
                    case 1:
                        seatNum = _in.Read_int();
                        break;
                    case 2:
                        closed = _in.Read_boolean();
                        break;
                    case 3:
                        player = _in.Read_pod<PlayerShowPOD>(PlayerShowPOD.DynamicFactory);
                        break;
                    default: _in.SkipBinary();break;
                }
            }
        }
		
		public RoomSeatPod Clone() {
            RoomSeatPod o = DynamicFactory();
            o.seatNum = seatNum;
            o.closed = closed;
            if (player != null) {
                o.player = player.Clone();
            }
            return o;
        }
        
        public void Clear() {
            seatNum = default;
            closed = default;
            player = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "RoomSeatPod [";
			str += "seatNum=";
			str += seatNum;
			str += ", closed=";
			str += closed;
			str += ", player=";
			str += player;
			str += "]";
			return str;
		}
		
	}
}